import axios from 'axios'
// 基准路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'
// 请求拦截器
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  // console.log(config)
  // 取出存的token
  let mytoken = localStorage.getItem('mytoken') || ''
  // 判断token是否存在
  if (mytoken) {
    config.headers['Authorization'] = mytoken
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})
// 删除角色权限
export const Delroles = (roleId, rightId) => axios.delete(`roles/${roleId}/rights/${rightId}`).then(res => res.data)
// 添加角色
export const AddroleInfo = obj => axios.post('/roles', obj).then(res => res.data)
// 编辑角色
export const EaitroleInfos = obj => axios.put(`roles/${obj.id}`, obj).then(res => res.data)
// 删除角色
export const Delroleinfo = id => axios.delete(`roles/${id}`).then(res => res.data)
// 权限列表
export const roleList = type => axios.get(`rights/${type}`).then(res => res.data)
// 修改角色权限
export const modifyUserrole = (roleId, rights) => axios.post(`/roles/${roleId}/rights`, {rids: rights}).then(res => res.data)
